/*
 * Л.р. 4, задание 1, вариант 3
 */
package calcInheritance;

import java.util.Scanner;

public class Program {

    public static void main(String[] args) {
        int mode;
        String repeat;
        String action;
        double result = Double.NaN;
        boolean isActionCompleted = false;
        OrdinaryCalc parentRef;
        OrdinaryCalc simpleCalc = new OrdinaryCalc();
        AdvancedCalc coolCalc = new AdvancedCalc();
        Scanner sc = new Scanner(System.in);

        do {
            System.out.println("Выберите режим работы (1 - обычный, 2 - инженерный): ");
            mode = sc.nextInt();
            if (mode == 1) {
                parentRef = simpleCalc;
                System.out.println("\nEnter action (+, -, *, /)");
            } else {
                if (mode == 2) {
                    parentRef = coolCalc;
                    System.out.println("\nEnter action (+, -, *, /, exp, octal)");
     } else {
                    System.out.println("\nНедопустимый режим!!! Калькулятор сломался!");
                    break;
                }
            }
            action = sc.next();
            isActionCompleted = false;
            if ((action.equals("+")) || (action.equals("-"))
                    || (action.equals("*")) || (action.equals("/"))) {
                System.out.println("Enter first number: ");
                parentRef.setNum1(sc.nextDouble());
                System.out.println("Enter second number: ");
                parentRef.setNum2(sc.nextDouble());
            }
            switch (action) {
                case "+":
                    result = parentRef.add();
                    isActionCompleted = true;
                    break;
                case "-":
                    result = parentRef.sub();
                    isActionCompleted = true;
                    break;
                case "*":
                    result = parentRef.mul();
                    isActionCompleted = true;
                    break;
                case "/":
                    result = parentRef.div();
                    isActionCompleted = true;
                    break;
                case "exp":
                    System.out.println("Enter int a, -5 <= a <= 5: ");
                    coolCalc.setNum3(sc.nextInt());
                    result = coolCalc.exp();
                    isActionCompleted = true;
                    break;
                case "octal":
                    System.out.println("Enter int decimal number > 0: ");
                    coolCalc.setNum3(sc.nextInt());
                    result = coolCalc.decimalToOctal();
                    isActionCompleted = true;
                    break;
                default:
                    System.out.println("You've entered wrong sign!!!");
                    break;
            }
            if (isActionCompleted) {
                System.out.println("Result is " + result);
            }
            System.out.println("Would you like to repeat? (y/n)");
            repeat = sc.next();
        } while (!repeat.equals("n"));
        sc.close();
    }
}
